//
//  MYNewFeatureController.m
//  MYChatting
//
//  Created by mac on 16/8/17.
//  Copyright © 2016年 lhf. All rights reserved.
//

#import "MYNewFeatureController.h"
#import "MYNewFeatureCell.h"

#define imageCount 4

@interface MYNewFeatureController ()

@end

@implementation MYNewFeatureController

static NSString * const reuseIdentifier = @"Cell";

#warning 注意手码时，设置flowLayout必须在init初始化方法中，其他比如initWithCollectionViewLayout:方法中也是不行的，必须在控制器初始化方法中
- (instancetype)init{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = kScreenSize.size;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 0;
    flowLayout.minimumInteritemSpacing = 0;
    
    
    return [super initWithCollectionViewLayout:flowLayout];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
     self.collectionView.pagingEnabled = YES;
    //解决第一个 最后一个拖拽留黑的问题
    self.collectionView.bounces = NO;
    self.collectionView.showsHorizontalScrollIndicator = NO;
   
    
    // Register cell classes
    [self.collectionView registerClass:[MYNewFeatureCell class] forCellWithReuseIdentifier:reuseIdentifier];
    

}



#pragma mark <UICollectionViewDataSource>




- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return imageCount;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    MYNewFeatureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
   // cell.backgroundColor = [self randColor];
    cell.index = indexPath.item;
    
    return cell;
}

//- (UIColor *)randColor{
//    CGFloat r = arc4random_uniform(256.0)/255.0;
//    CGFloat g = arc4random_uniform(256.0) / 255.0;
//    CGFloat b = arc4random_uniform(256.0)/255.0;
//    return [UIColor colorWithRed:r green:g blue:b alpha:1.0];
//}

- (void)collectionView:(nonnull UICollectionView *)collectionView didEndDisplayingCell:(nonnull UICollectionViewCell *)cell forItemAtIndexPath:(nonnull NSIndexPath *)indexPath{
    MYNewFeatureCell *newcell = [collectionView.visibleCells lastObject];
   NSIndexPath *newindexpath = [collectionView indexPathForCell:newcell];
    if (newindexpath.item == imageCount - 1) {
        [newcell startAnimation];
    }
}


@end
